import java.util.Stack;

class MinStack {
    Stack<Integer> stack =new Stack<>();
    Stack<Integer> minStack =new Stack<>();
    public MinStack() {

    }

    public void push(int val) {
        stack.push(val);
        if(minStack.isEmpty()){
            minStack.push(val);
            return;
        }
        if(val<=minStack.peek()){
            minStack.push(val);
        }
    }

    public void pop() {
//        int len=stack.pop();
        if((int)stack.pop()==minStack.peek()){
            minStack.pop();
        }
    }

    public int top() {
        return stack.peek();
    }

    public int getMin() {
        return minStack.peek();
    }
}
